set mem 500m
set more off
*Create datasets to save the results 
clear
set obs 1
gen b1=.
gen b2=.
gen b3=.
gen nobs=.
gen sigma=.
gen trial=.
gen rsq=.
save "C:\OLS_simulation1\ols_result1.dta", replace


*OLS_sample1
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample1.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = `i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample2
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample2.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 100+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample3
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample3.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 200+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample4
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample4.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 300+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample5
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample5.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 400+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample6
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample6.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 500+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample7
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample7.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 600+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample8
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample8.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 700+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample9
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample9.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 800+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace

*OLS_sample10
clear 
foreach i of num 1/100{
use "C:\OLS_simulation1\sample10.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 900+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation1\ols_result1.dta"
capture save "C:\OLS_simulation1\ols_result1.dta", replace
}
sort trial
capture save "C:\OLS_simulation1\ols_result1.dta", replace
